package org.codeanalyzer.model;

public class ApiMethod extends ApiItem
{
    @SuppressWarnings("unused")
    private final ApiClass apiClass;
    private final String simpleName;
    private final String parameters;
    private final String returnType;
    private final String modifiers;
    private int coverageCount = 0;

    public ApiMethod(ApiClass apiClass, String simpleName, String modifiers, String returnType, String parameters)
    {
        super(generateName(apiClass.getName(), simpleName, modifiers, returnType, parameters));
        this.apiClass = apiClass;
        this.simpleName = simpleName;
        this.modifiers = modifiers;
        this.returnType = returnType;
        this.parameters = parameters;
    }

    public String getSimpleName()
    {
        return simpleName;
    }

    public String getParameters()
    {
        return parameters;
    }

    public String getReturnType()
    {
        return returnType;
    }

    public String getModifiers()
    {
        return modifiers;
    }

    public static String generateName(String className, String methodName, String modifiers, String returnType,
        String parameters)
    {
        return modifiers + " " + returnType + " " + className + "." + methodName + "(" + parameters + ")";
    }

    public static String generateKey(String methodName, String parameters)
    {
        return methodName + "(" + parameters + ")";
    }

    public static String generateKey(String methodNameWithParameters)
    {
        return methodNameWithParameters;
    }

    String getKey()
    {
        return simpleName + "(" + parameters + ")";
    }

    @Override
    public int compareTo(ApiItem o)
    {
        if (o instanceof ApiMethod)
            return getKey().compareTo(((ApiMethod)o).getKey());
        return super.compareTo(o);
    }

    public boolean isCovered()
    {
        return coverageCount > 0;
    }

    public void incrementCoverageCount()
    {
        coverageCount++;
    }
}
